From 73fac24a3a4ce64b507c0a0c1baa83f32d148153 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 10 Jan 2012 23:49:21 +0100 Subject: [PATCH] shorthand: Add a "pack_first_element" pack function And use it where appropriate. See the docs in the function for what it does. --- gtk/gtkcssshorthandpropertyimpl.c | 48 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c index d2a62ea348..c3e6332a29 100644 --- a/gtk/gtkcssshorthandpropertyimpl.c +++ b/gtk/gtkcssshorthandpropertyimpl.c @@ -797,17 +797,30 @@ unpack_border_color (GtkCssShorthandProperty *shorthand, } static void -pack_border_color (GtkCssShorthandProperty *shorthand, - GValue *value, - GtkStyleProperties *props, - GtkStateFlags state) +pack_first_element (GtkCssShorthandProperty *shorthand, + GValue *value, + GtkStyleProperties *props, + GtkStateFlags state) { - /* NB: We are a color property, so we have to resolve to a color here. - * So we just resolve to a color. We pick one and stick to it. - * Lesson learned: Don't query border-color shorthand, query the + GtkCssStyleProperty *prop; + const GValue *v; + guint i; + + /* NB: This is a fallback for properties that originally were + * not used as shorthand. We just pick the first subproperty + * as a representative. + * Lesson learned: Don't query the shorthand, query the * real properties instead. */ - g_value_unset (value); - gtk_style_properties_get_property (props, "border-top-color", state, value); + for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++) + { + prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0); + v = _gtk_style_properties_peek_property (props, prop, state); + if (v) + { + g_value_copy (v, value); + return; + } + } } static GParameter * @@ -837,19 +850,6 @@ unpack_border_style (GtkCssShorthandProperty *shorthand, return parameter; } -static void -pack_border_style (GtkCssShorthandProperty *shorthand, - GValue *value, - GtkStyleProperties *props, - GtkStateFlags state) -{ - /* NB: We can just resolve to a style. We pick one and stick to it. - * Lesson learned: Don't query border-style shorthand, query the - * real properties instead. */ - g_value_unset (value); - gtk_style_properties_get_property (props, "border-top-style", state, value); -} - static void _gtk_css_shorthand_property_register (const char *name, GType value_type, @@ -931,13 +931,13 @@ _gtk_css_shorthand_property_init_properties (void) border_color_subproperties, parse_border_color, unpack_border_color, - pack_border_color); + pack_first_element); _gtk_css_shorthand_property_register ("border-style", GTK_TYPE_BORDER_STYLE, border_style_subproperties, parse_border_style, unpack_border_style, - pack_border_style); + pack_first_element); _gtk_css_shorthand_property_register ("border-image", G_TYPE_NONE, border_image_subproperties, -- 2.30.2